<template>
  <el-dialog :title="dialogTit"
             append-to-body
             :visible.sync="dialogVisible"
             width="800px">
    <el-carousel ref="imageBox"
                 indicator-position="outside"
                 :initial-index="initIndex"
                 :autoplay="false"
                 height="600px">
      <el-carousel-item v-for="(item,index) in picList"
                        :key="index">
        <el-image class="img-item"
                  :src="item"
                  fit="contain"></el-image>
      </el-carousel-item>
    </el-carousel>
    <!-- <div class="img-wrap">
      <el-image class="img-item" :src="picList"
                fit="contain"></el-image>
    </div> -->
    <div slot="footer"
         class="dialog-footer">
      <el-button @click="dialogVisible = false"
                 size="small">关 闭</el-button>
    </div>
  </el-dialog>
</template>

<script>
export default {
  props: {
    dialogTit: {
      type: String,
      default: '查看图片'
    },
  },
  data() {
    return {
      dialogVisible: false,
      picList: [], // 图片地址列表
      initIndex: 0, // 初始状态激活的图片的索引
    }
  },
  methods: {
    open(urls = [], picIndex = 0) {
      console.log(picIndex)
      this.picList = urls;
      this.initIndex = picIndex;
      this.dialogVisible = true
      this.$nextTick(() => {
        this.$refs.imageBox.setActiveItem(picIndex)
      })
    }
  },
}
</script>

<style lang="scss" scoped>
.img-item {
  width: 760px;
  height: 600px;
  background-color: #ccc;
}
/deep/.el-dialog__body {
  padding: 0 20px;
}
</style>